﻿using System;
using System.Collections;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using RaGE.Properties;

namespace RaGE
{
    public partial class MainWindow
    {
        private void ElementsMenu(bool state)
        {
            switch (state)
            {
                case true:
                    MenuItem_EditElements.Visible = true;
                    MenuItemTools.Visible = true;
                    ELExportMenuItem.Visible = true;
                    OpenMenuItem.Visible = false;
                    LoadELMenuItem.Visible = true;
                    PWELSave.Visible = true;
                    SaveMenuItem.Visible = false;

                    break;

                case false:
                    MenuItem_EditElements.Visible = false;
                    MenuItemTools.Visible = false;
                    ELExportMenuItem.Visible = false;
                    OpenMenuItem.Visible = true;
                    LoadELMenuItem.Visible = false;
                    PWELSave.Visible = false;
                    SaveMenuItem.Visible = true;
                    
                    break;
            }
        }

        private void ClickLoad(object sender, EventArgs e)
        {
            var eLoad = new OpenFileDialog();
            eLoad.Filter = Resources.ElementsFilter;

            if (eLoad.ShowDialog() != DialogResult.OK || !File.Exists(eLoad.FileName)) return;

            try
            {
                Cursor = Cursors.AppStarting;
                ProgressBar.Style = ProgressBarStyle.Marquee;

                ELC = new EListCollection(eLoad.FileName);

                if (ELC.ConversationListIndex > -1 && ELC.Lists.Length > ELC.ConversationListIndex)
                    ConversationList =
                        new EListConversation((byte[]) ELC.Lists[ELC.ConversationListIndex].elementValues[0][0]);

                dataGridView_ELItem.Rows.Clear();
                listBox_ELItems.Items.Clear();
                comboBox_ELLists.Items.Clear();

                for (var l = 0; l < ELC.Lists.Length; l++)
                {
                    comboBox_ELLists.Items.Add("[" + l + "]: " + ELC.Lists[l].listName + " (" + ELC.Lists[l].elementValues.Length + ")");
                }

                Text = Resources.RaGEVersionTitle + Common.Version + Resources.LSParen + eLoad.FileName + Resources.RPAREN;

                ProgressBar.Style = ProgressBarStyle.Continuous;
                Cursor = Cursors.Default;
            }
            catch
            {
                MessageBox.Show(Resources.ErrLoadElements);
                ProgressBar.Style = ProgressBarStyle.Continuous;
                Cursor = Cursors.Default;
            }
        }

        private void ClickSave(object sender, EventArgs e)
        {

            var eSave = new SaveFileDialog();
            eSave.InitialDirectory = Environment.CurrentDirectory;
            eSave.Filter = Resources.ElementsFilter;

            if (eSave.ShowDialog() != DialogResult.OK || eSave.FileName == "") return;

            try
            {
                Cursor = Cursors.AppStarting;
                ProgressBar.Style = ProgressBarStyle.Marquee;

                if (ELC.ConversationListIndex > -1 && ELC.Lists.Length > ELC.ConversationListIndex)
                    ELC.Lists[ELC.ConversationListIndex].elementValues[0][0] = ConversationList.GetBytes();

                ELC.Save(eSave.FileName);
                ProgressBar.Style = ProgressBarStyle.Continuous;
                Cursor = Cursors.Default;
            }
            catch
            {
                MessageBox.Show(Resources.SavingError);
                ProgressBar.Style = ProgressBarStyle.Continuous;
                Cursor = Cursors.Default;
            }
        }

        private void ClickExport(object sender, EventArgs e)
        {
            var eSave = new SaveFileDialog();
            eSave.Filter = Resources.ElementsFilter;

            if (eSave.ShowDialog() != DialogResult.OK || eSave.FileName == "") return;

            try
            {
                Cursor = Cursors.WaitCursor;
                ProgressBar.Style = ProgressBarStyle.Marquee;
                var rulesFile = Application.StartupPath + "\\rules\\" + ((ToolStripMenuItem)sender).Text.Replace("==>", "=") + ".rules";
                ELC.Export(rulesFile, eSave.FileName);
                ProgressBar.Style = ProgressBarStyle.Continuous;
                Cursor = Cursors.Default;
            }
            catch
            {
                MessageBox.Show(Resources.ExportError);
                ProgressBar.Style = ProgressBarStyle.Continuous;
                Cursor = Cursors.Default;
            }
        }
        
        private void ChangeList(object sender, EventArgs ea)
        {
            if (comboBox_ELLists.SelectedIndex <= -1) return;

            var l = comboBox_ELLists.SelectedIndex;
            listBox_ELItems.Items.Clear();
            textBox_ELOffset.Text = ELC.GetOffset(l);
            dataGridView_ELItem.Rows.Clear();

            if (l != ELC.ConversationListIndex)
            {
                for (var e = 0; e < ELC.Lists[l].elementValues.Length; e++)
                {
                    // Find Position for Name
                    var pos = -1;

                    for (var i = 0; i < ELC.Lists[l].elementFields.Length; i++)
                    {
                        if (ELC.Lists[l].elementFields[i] != "Name") continue;

                        pos = i;
                        break;
                    }

                    if (ELC.Lists[l].elementFields[0] == "ID")
                        listBox_ELItems.Items.Add("[" + e + "]: " + ELC.GetValue(l, e, 0) + " - " +
                                                  ELC.GetValue(l, e, pos));
                    else
                        listBox_ELItems.Items.Add("[" + e + "]: " + ELC.GetValue(l, e, pos));
                }
            }
            else
                for (var e = 0; e < ConversationList.DialogCount; e++)
                    listBox_ELItems.Items.Add("[" + e + "]: " + ConversationList.Dialogs[e].DialogID + " - Dialog");
        }

        private void ChangeItem(object sender, EventArgs ea)
        {
            var l = comboBox_ELLists.SelectedIndex;
            var e = listBox_ELItems.SelectedIndex;
            var scroll = dataGridView_ELItem.FirstDisplayedScrollingRowIndex;
            dataGridView_ELItem.Rows.Clear();

            if (l != ELC.ConversationListIndex)
            {
                if (e > -1)
                {
                    for (var f = 0; f < ELC.Lists[l].elementValues[e].Length; f++)
                    {
                        dataGridView_ELItem.Rows.Add(new object[]
                        {
                            ELC.Lists[l].elementFields[f],
                            ELC.Lists[l].elementTypes[f],
                            ELC.GetValue(l, e, f)
                        });
                        
                        dataGridView_ELItem.Rows[f].HeaderCell.Value =
                            f.ToString(CultureInfo.InvariantCulture);
                    }
                }
            }
            else
            {
                if (e > -1)
                {
                    dataGridView_ELItem.Rows.Add(new object[] { "Dialog ID", "int32",
                        ConversationList.Dialogs[e].DialogID.ToString(CultureInfo.InvariantCulture) });
                    dataGridView_ELItem.Rows.Add(new object[] { "Dialog Name", "wstring:128", ConversationList.Dialogs[e].GetText() });

                    for (var q = 0; q < ConversationList.Dialogs[e].QuestionCount; q++)
                    {
                        dataGridView_ELItem.Rows.Add(new object[] { "Question_" + q + " - ID", "int32",
                            ConversationList.Dialogs[e].Questions[q].QuestionID.ToString(CultureInfo.InvariantCulture) });
                        dataGridView_ELItem.Rows.Add(new object[] { "Question_" + q + " - Control", "int32",
                            ConversationList.Dialogs[e].Questions[q].Control.ToString(CultureInfo.InvariantCulture) });
                        dataGridView_ELItem.Rows.Add(new object[] { "Question_" + q + " - Text", "wstring:" +
                            ConversationList.Dialogs[e].Questions[q].QuestionTextLength, ConversationList.Dialogs[e].Questions[q].GetText() });

                        for (var c = 0; c < ConversationList.Dialogs[e].Questions[q].ChoiceQount; c++)
                        {
                            dataGridView_ELItem.Rows.Add(new object[] { "Question_" + q + " - Choice_" + c + " - Control", "int32",
                                ConversationList.Dialogs[e].Questions[q].Choices[c].Control.ToString(CultureInfo.InvariantCulture) });
                            dataGridView_ELItem.Rows.Add(new object[] { "Question_" + q + " - Choice_" + c + " - Text", "wstring:132",
                                ConversationList.Dialogs[e].Questions[q].Choices[c].GetText() });
                        }
                    }
                }

            }
            if (scroll > -1) dataGridView_ELItem.FirstDisplayedScrollingRowIndex = scroll;
        }

        private void ChangeOffset(object sender, EventArgs e)
        {
            ELC.SetOffset(comboBox_ELLists.SelectedIndex, textBox_ELOffset.Text);
        }

        private void ChangeValue(object sender, DataGridViewCellEventArgs ea)
        {
            try
            {
                if (ELC == null || ea.ColumnIndex <= -1) return;

                var l = comboBox_ELLists.SelectedIndex;
                var e = listBox_ELItems.SelectedIndex;

                if (l != ELC.ConversationListIndex)
                {
                    ELC.SetValue(l, e, ea.RowIndex, Convert.ToString(dataGridView_ELItem.CurrentCell.Value));

                    if (ea.RowIndex == 0 || dataGridView_ELItem.Rows[ea.RowIndex].Cells[0].Value.ToString() == "Name")
                    {
                        // change the vakues in the listbox depending on new name & id

                        // Find Position for Name
                        var pos = -1;

                        for (var i = 0; i < ELC.Lists[l].elementFields.Length; i++)
                        {
                            if (ELC.Lists[l].elementFields[i] != "Name") continue;

                            pos = i;
                            break;
                        }

                        listBox_ELItems.SelectedIndexChanged -= ChangeItem;
                        listBox_ELItems.Items[e] = "[" + e + "]: " + ELC.GetValue(l, e, 0) + " - " + ELC.GetValue(l, e, pos);
                        listBox_ELItems.SelectedIndexChanged += ChangeItem;
                    }
                }
                else
                {
                    //check which item was changed (by field name)
                    var fieldName = dataGridView_ELItem[0, ea.RowIndex].Value.ToString();

                    if (fieldName == "Dialog ID")
                    {
                        ConversationList.Dialogs[listBox_ELItems.SelectedIndex].DialogID = Convert.ToInt32(dataGridView_ELItem.CurrentCell.Value);
                        return;
                    }

                    if (fieldName == "Dialog Name")
                    {
                        ConversationList.Dialogs[listBox_ELItems.SelectedIndex].SetText(dataGridView_ELItem.CurrentCell.Value.ToString());
                        return;
                    }

                    if (fieldName.StartsWith("Question_") && fieldName.EndsWith(" - ID"))
                    {
                        var q = Convert.ToInt32(fieldName.Replace("Question_", "").Replace(" - ID", ""));
                        ConversationList.Dialogs[listBox_ELItems.SelectedIndex].Questions[q].QuestionID =
                            Convert.ToInt32(dataGridView_ELItem.CurrentCell.Value);
                        return;
                    }

                    if (fieldName.StartsWith("Question_") && fieldName.Contains("Choice_") && fieldName.EndsWith(" - Control"))
                    {
                        var s = fieldName.Replace("Question_", "").Replace(" - Choice_", ";").Replace(" - Control", "").Split(new[] { ';' });
                        var q = Convert.ToInt32(s[0]);
                        var c = Convert.ToInt32(s[1]);
                        ConversationList.Dialogs[listBox_ELItems.SelectedIndex].Questions[q].Choices[c].Control =
                            Convert.ToInt32(dataGridView_ELItem.CurrentCell.Value);
                        return;
                    }

                    if (fieldName.StartsWith("Question_") && fieldName.Contains("Choice_") && fieldName.EndsWith(" - Text"))
                    {
                        var s = fieldName.Replace("Question_", "").Replace(" - Choice_", ";").Replace(" - Text", "").Split(new[] { ';' });
                        var q = Convert.ToInt32(s[0]);
                        var c = Convert.ToInt32(s[1]);
                        ConversationList.Dialogs[listBox_ELItems.SelectedIndex].Questions[q].Choices[c].
                            SetText(dataGridView_ELItem.CurrentCell.Value.ToString());
                        return;
                    }

                    if (fieldName.StartsWith("Question_") && fieldName.EndsWith(" - Control"))
                    {
                        var q = Convert.ToInt32(fieldName.Replace("Question_", "").Replace(" - Control", ""));
                        ConversationList.Dialogs[listBox_ELItems.SelectedIndex].Questions[q].Control =
                            Convert.ToInt32(dataGridView_ELItem.CurrentCell.Value);
                        return;
                    }

                    if (fieldName.StartsWith("Question_") && fieldName.EndsWith(" - Text"))
                    {
                        var q = Convert.ToInt32(fieldName.Replace("Question_", "").Replace(" - Text", ""));
                        ConversationList.Dialogs[listBox_ELItems.SelectedIndex].Questions[q].SetText(dataGridView_ELItem.CurrentCell.Value.ToString());
                        dataGridView_ELItem[1, ea.RowIndex].Value =
                            "wstring:" + ConversationList.Dialogs[listBox_ELItems.SelectedIndex].Questions[q].QuestionTextLength;
                    }
                }
            }
            catch
            {
                MessageBox.Show(Resources.ErrChanging);
            }
        }

        private void ClickSearch(object sender, EventArgs ea)
        {
            var id = textBox_search.Text;
            var l = comboBox_ELLists.SelectedIndex;

            if (l < 0) l = 0;

            var e = listBox_ELItems.SelectedIndex + 1;

            if (e < 0) e = 0;

            if (ELC == null || ELC.Lists == null) return;

            for ( ; l < ELC.Lists.Length; l++)
            {
                var pos = 0;

                for (var i = 0; i < ELC.Lists[l].elementFields.Length; i++)
                {
                    if (ELC.Lists[l].elementFields[i] != "Name") continue;

                    pos = i;
                    break;
                }

                for ( ; e < ELC.Lists[l].elementValues.Length; e++)
                {
                    if (id != ELC.GetValue(l, e, 0) && !ELC.GetValue(l, e, pos).Contains(id)) continue;

                    comboBox_ELLists.SelectedIndex = l;
                    listBox_ELItems.SelectedIndex = e;
                    return;
                }
                e = 0;
            }
            MessageBox.Show(Resources.SearchNoResults);
        }

        private void ClickDeleteItem(object sender, EventArgs ea)
        {
            var l = comboBox_ELLists.SelectedIndex;
            var e = listBox_ELItems.SelectedIndex;

            if (l != ELC.ConversationListIndex)
            {
                if (l > -1 && e > -1)
                {
                    ELC.Lists[l].RemoveItem(e);
                    dataGridView_ELItem.Rows.Clear();
                    listBox_ELItems.Items.RemoveAt(e);
                    comboBox_ELLists.Items[l] = "[" + l + "]: " +
                                                ELC.Lists[l].listName + " (" + ELC.Lists[l].elementValues.Length + ")";

                    if (e < listBox_ELItems.Items.Count)
                        listBox_ELItems.SelectedIndex = e;
                    else
                    {
                        if (listBox_ELItems.Items.Count > -1)
                            listBox_ELItems.SelectedIndex = listBox_ELItems.Items.Count - 1;
                    }
                }
            }
            else
                MessageBox.Show(Resources.OpNoSupportList + ELC.ConversationListIndex.ToString(CultureInfo.InvariantCulture));
        }

        private void ClickCloneItem(object sender, EventArgs ea)
        {
            var l = comboBox_ELLists.SelectedIndex;
            var e = listBox_ELItems.SelectedIndex;

            if (l != ELC.ConversationListIndex)
            {
                if (l > -1 && e > -1)
                {
                    var o = new object[ELC.Lists[l].elementValues[e].Length];
                    ELC.Lists[l].elementValues[e].CopyTo(o, 0);
                    ELC.Lists[l].AddItem(o);
                    listBox_ELItems.Items.Add(listBox_ELItems.Items[e]);
                    comboBox_ELLists.Items[l] = "[" + l + "]: " + ELC.Lists[l].listName + " (" +
                        ELC.Lists[l].elementValues.Length + ")";
                    listBox_ELItems.SelectedIndex = listBox_ELItems.Items.Count - 1;
                }
            }
            else
                MessageBox.Show(Resources.OpNoSupportList +
                    ELC.ConversationListIndex.ToString(CultureInfo.InvariantCulture));
        }

        private void ClickLogicReplace(object sender, EventArgs e)
        {
            if (ELC != null)
            {
                (new ReplaceWindow(ELC)).ShowDialog();

                var itemIndex = listBox_ELItems.SelectedIndex;
                ChangeList(null, null);
                listBox_ELItems.SelectedIndex = itemIndex;
            }
            else
                MessageBox.Show(Resources.NoFileLoaded);
        }

        private void ClickVersion(object sender, EventArgs e)
        {
            var eLoad = new OpenFileDialog();
            eLoad.Filter = Resources.ElementsFilter;

            if (eLoad.ShowDialog() != DialogResult.OK || !File.Exists(eLoad.FileName)) return;

            var fs = File.OpenRead(eLoad.FileName);
            var br = new BinaryReader(fs);
            var version = br.ReadInt16();

            br.Close();
            fs.Close();

            MessageBox.Show(Resources.File + eLoad.FileName + Resources.CRCRVersion + version.ToString(CultureInfo.InvariantCulture));
        }

        private void ClickConfig(object sender, EventArgs e)
        {
            (new ConfigWindow()).Show();
        }

        private void ClickExportItem(object sender, EventArgs ea)
        {
            var l = comboBox_ELLists.SelectedIndex;
            var e = listBox_ELItems.SelectedIndex;

            if (l != ELC.ConversationListIndex)
            {
                if (l > -1 && e > -1)
                {
                    var eSave = new SaveFileDialog();
                    eSave.Filter = Resources.UnicodeTxtFilter;

                    if (eSave.ShowDialog() == DialogResult.OK && eSave.FileName != "")
                    {
                        try
                        {
                            Cursor = Cursors.AppStarting;
                            ELC.Lists[l].ExportItem(eSave.FileName, e);
                            Cursor = Cursors.Default;
                        }
                        catch
                        {
                            MessageBox.Show(Resources.ErrExportUnicode);
                            Cursor = Cursors.Default;
                        }
                    }
                }
            }
            else
                MessageBox.Show(Resources.OpNoSupportList +
                    ELC.ConversationListIndex.ToString(CultureInfo.InvariantCulture));
        }

        private void ClickImportItem(object sender, EventArgs ea)
        {
            var l = comboBox_ELLists.SelectedIndex;
            var e = listBox_ELItems.SelectedIndex;

            if (l != ELC.ConversationListIndex)
            {
                if (l > -1 && e > -1)
                {
                    var eLoad = new OpenFileDialog();
                    eLoad.Filter = Resources.UnicodeTxtFilter;

                    if (eLoad.ShowDialog() == DialogResult.OK && File.Exists(eLoad.FileName))
                    {
                        try
                        {
                            Cursor = Cursors.AppStarting;
                            ELC.Lists[l].ImportItem(eLoad.FileName, e);
                            ChangeList(null, null);
                            listBox_ELItems.SelectedIndex = e;
                            Cursor = Cursors.Default;
                        }
                        catch
                        {
                            MessageBox.Show(Resources.ErrUnicodeImport);
                            Cursor = Cursors.Default;
                        }
                    }
                }
            }
            else
                MessageBox.Show(Resources.OpNoSupportList +
                    ELC.ConversationListIndex.ToString(CultureInfo.InvariantCulture));
        }

        private void ClickNPCExport(object sender, EventArgs e)
        {
            var save = new SaveFileDialog();
            save.InitialDirectory = Environment.CurrentDirectory;
            save.Filter = Resources.TextFilter;

            if (save.ShowDialog() != DialogResult.OK || save.FileName == "") return;

            try
            {
                Cursor = Cursors.AppStarting;
                ProgressBar.Style = ProgressBarStyle.Marquee;

                var sw = new StreamWriter(save.FileName, false, Encoding.Unicode);

                for (var i = 0; i < ELC.Lists[38].elementValues.Length; i++)
                    sw.WriteLine(ELC.GetValue(38, i, 0) + "\t" + ELC.GetValue(38, i, 2));

                for (var i = 0; i < ELC.Lists[57].elementValues.Length; i++)
                    sw.WriteLine(ELC.GetValue(57, i, 0) + "\t" + ELC.GetValue(57, i, 1));

                sw.Close();

                ProgressBar.Style = ProgressBarStyle.Continuous;
                Cursor = Cursors.Default;
            }
            catch
            {
                MessageBox.Show(Resources.ErrSaving);
                ProgressBar.Style = ProgressBarStyle.Continuous;
                Cursor = Cursors.Default;
            }
        }

        private void ClickJoinEL(object sender, EventArgs e)
        {
            var eJoin = new JoinWindow();

            if (eJoin.ShowDialog() != DialogResult.OK) return;

            if (!File.Exists(eJoin.FileName)) return;

            if (eJoin.LogDirectory == "" || !Directory.Exists(eJoin.LogDirectory))
            {
                eJoin.LogDirectory = eJoin.FileName + ".JOIN";
                Directory.CreateDirectory(eJoin.LogDirectory);
            }

            if (eJoin.BackupNew)
                Directory.CreateDirectory(eJoin.LogDirectory + "\\added.backup");

            if (eJoin.BackupChanged)
                Directory.CreateDirectory(eJoin.LogDirectory + "\\replaced.backup");

            if (eJoin.BackupMissing)
                Directory.CreateDirectory(eJoin.LogDirectory + "\\removed.backup");

            try
            {
                Cursor = Cursors.WaitCursor;
                ProgressBar.Style = ProgressBarStyle.Marquee;
                var nELC = new EListCollection(Application.StartupPath + "\\configs\\" + ((ToolStripMenuItem)sender).Text + ".cfg", eJoin.FileName);

                if (ELC.ConfigFile != nELC.ConfigFile)
                    MessageBox.Show(Resources.MergeWarning, Resources.WARNING);

                if (ELC.ConversationListIndex > -1 && nELC.Lists.Length > ELC.ConversationListIndex)
                    ConversationList = new EListConversation((byte[]) nELC.Lists[ELC.ConversationListIndex].elementValues[0][0]);

                var sw = new StreamWriter(eJoin.LogDirectory + "\\LOG.TXT", false, Encoding.Unicode);

                for (var l = 0; l < ELC.Lists.Length; l++)
                {
                    if (l == ELC.ConversationListIndex) continue;

                    var report = ELC.Lists[l].JoinElements(nELC.Lists[l], l, eJoin.AddNew, eJoin.BackupNew,
                        eJoin.ReplaceChanged, eJoin.BackupChanged, eJoin.RemoveMissing, eJoin.BackupMissing, eJoin.LogDirectory +
                        "\\added.backup", eJoin.LogDirectory + "\\replaced.backup", eJoin.LogDirectory + "\\removed.backup");
                    report.Sort();

                    if (report.Count > 0)
                    {
                        sw.WriteLine("List " + l + ": " + report.Count + " Item(s) Affected");
                        sw.WriteLine();

                        foreach (var t in report)
                            sw.WriteLine((string) t);

                        sw.WriteLine();
                    }

                    comboBox_ELLists.Items[l] = "[" + l + "]: " + ELC.Lists[l].listName + " (" + ELC.Lists[l].elementValues.Length + ")";
                }

                sw.Close();

                if (comboBox_ELLists.SelectedIndex > -1)
                    ChangeList(null, null);

                ProgressBar.Style = ProgressBarStyle.Continuous;
                Cursor = Cursors.Default;
            }
            catch
            {
                MessageBox.Show(Resources.LoadingError);
                ProgressBar.Style = ProgressBarStyle.Continuous;
                Cursor = Cursors.Default;
            }
        }

        private void ClickNPCAIExport(object sender, EventArgs e)
        {
            var save = new SaveFileDialog();
            save.InitialDirectory = Environment.CurrentDirectory;
            save.Filter = Resources.TextFilter;

            if (save.ShowDialog() != DialogResult.OK || save.FileName == "") return;

            try
            {
                Cursor = Cursors.AppStarting;
                ProgressBar.Style = ProgressBarStyle.Marquee;

                var sw = new StreamWriter(save.FileName, false, Encoding.Unicode);

                for (var i = 0; i < ELC.Lists[38].elementValues.Length; i++)
                    sw.WriteLine(ELC.GetValue(38, i, 0) + "\t" + ELC.GetValue(38, i, 2) + "\t" + ELC.GetValue(38, i, 64));

                sw.Close();

                ProgressBar.Style = ProgressBarStyle.Continuous;
                Cursor = Cursors.Default;
            }
            catch
            {
                MessageBox.Show(Resources.ErrSaving);
                ProgressBar.Style = ProgressBarStyle.Continuous;
                Cursor =Cursors.Default;
            }
        }
        
        private void ClickSkillValidate(object sender, EventArgs e)
        {
            if (ELC == null) return;

            var mobSkills = new ArrayList();

            // check all monster skills (list 38 fields 119, 121, 123, 125, 127, 129)
            for (var n = 0; n < ELC.Lists[38].elementValues.Length; n++)
            {
                for (var f = 119; f < 130; f += 2)
                {
                    var skill = ELC.GetValue(38, n, f);

                    if (Convert.ToInt32(skill) > 846)
                        mobSkills.Add("Invalid Skill: " + skill + " (Monster: " + ELC.GetValue(38, n, 0) + ")");
                }
            }

            if (mobSkills.Count == 0)
                MessageBox.Show(Resources.OKNoInvalid);
            else
            {
                var message = mobSkills.Cast<object>().Aggregate("", (current, t) => current + ((string) t + "\r\n"));

// ReSharper disable ObjectCreationAsStatement
                new DebugWindow("Invalid Skills", message);
// ReSharper restore ObjectCreationAsStatement
            }
        }

        private void ClickPropertyValidate(object sender, EventArgs e)
        {
            if (ELC == null) return;

            var properties = new ArrayList();
            string attribute;
                
            // weapons (list 3, fields 43-201, +=2)
            for (var i = 0; i < ELC.Lists[3].elementValues.Length; i++)
            {
                for (var j = 43; j < 202; j += 2)
                {
                    attribute = ELC.GetValue(3, i, j);

                    if (Convert.ToInt32(attribute) > 1909)
                        properties.Add("Invalid Property: " + attribute + " (Weapon: " + ELC.GetValue(3, i, 0) + ")");
                }
            }

            // armors (list 6, fields 55-179, +=2)
            for (var i = 0; i < ELC.Lists[6].elementValues.Length; i++)
            {
                for (var j = 55; j < 180; j += 2)
                {
                    attribute = ELC.GetValue(6, i, j);

                    if (Convert.ToInt32(attribute) > 1909)
                        properties.Add("Invalid Property: " + attribute + " (Armor: " + ELC.GetValue(6, i, 0) + ")");
                }
            }

            // ornaments (list 9, fields 44-160, +=2)
            for (var i = 0; i < ELC.Lists[9].elementValues.Length; i++)
            {
                for (var j = 44; j < 161; j += 2)
                {
                    attribute = ELC.GetValue(9, i, j);

                    if (Convert.ToInt32(attribute) > 1909)
                        properties.Add("Invalid Property: " + attribute + " (Ornament: " + ELC.GetValue(9, i, 0) + ")");
                }
            }

            // soulgems (list 35, fields 11-12, +=1)
            for (var i = 0; i < ELC.Lists[35].elementValues.Length; i++)
            {
                for (var j = 11; j < 13; j++)
                {
                    attribute = ELC.GetValue(35, i, j);

                    if (Convert.ToInt32(attribute) > 1909)
                        properties.Add("Invalid Property: " + attribute + " (Soulgem: " + ELC.GetValue(35, i, 0) + ")");
                }
            }

            // complect boni (list 90, fields 15-19, +=1)
            for (var i = 0; i < ELC.Lists[90].elementValues.Length; i++)
            {
                for (var j = 15; j < 20; j++)
                {
                    attribute = ELC.GetValue(90, i, j);

                    if (Convert.ToInt32(attribute) > 1909)
                        properties.Add("Invalid Property: " + attribute + " (Complect Bonus: " + ELC.GetValue(90, i, 0) + ")");
                }
            }

            if (properties.Count == 0)
                MessageBox.Show(Resources.OkNoInvalidProps);
            else
            {
                var message = properties.Cast<object>().Aggregate("", (current, t) => current + ((string) t + "\r\n"));

                // ReSharper disable ObjectCreationAsStatement
                new DebugWindow("Invalid Properties", message);
                // ReSharper restore ObjectCreationAsStatement
            }
        }

        private void ClickTomeValidate(object sender, EventArgs e)
        {
            if (ELC == null) return;

            var properties = new ArrayList();

            for (var i = 0; i < ELC.Lists[112].elementValues.Length; i++)
            {
                for (var j = 4; j < 14; j++)
                {
                    var attribute = ELC.GetValue(112, i, j);

                    if (Convert.ToInt32(attribute) > 1909)
                        properties.Add("Invalid Property: " + attribute + " (Tome: " + ELC.GetValue(112, i, 0) + ")");
                }
            }

            if (properties.Count == 0)
                MessageBox.Show(Resources.OkNoInvalidTome);
            else
            {
                var message = properties.Cast<object>().Aggregate("", (current, t) => current + ((string) t + "\r\n"));

// ReSharper disable ObjectCreationAsStatement
                new DebugWindow("Invalid Tome Properties", message);
// ReSharper restore ObjectCreationAsStatement
            }
        }

        private void ClickSkillReplace(object sender, EventArgs e)
        {
            if (ELC == null) return;

            var load = new OpenFileDialog();
            load.InitialDirectory = Application.StartupPath + "\\replace";
            load.Filter = Resources.SkillReplaceFilter;

            if (load.ShowDialog() != DialogResult.OK || !File.Exists(load.FileName)) return;

            var skillTable = new SortedList();
            var sr = new StreamReader(load.FileName);
            var seperator = new[]{ "=" };

            while (!sr.EndOfStream)
            {
                var line = sr.ReadLine();

                if (line != null && (line.StartsWith("#") || !line.Contains("="))) continue;

                if (line == null) continue;

                var pair = line.Split(seperator, StringSplitOptions.RemoveEmptyEntries);

                if (pair.Length == 2) skillTable.Add(pair[0], pair[1]);
            }

            sr.Close();

            // change all monster skills (list 38 fields 119, 121, 123, 125, 127, 129)
            for (var n = 0; n < ELC.Lists[38].elementValues.Length; n++)
            {
                for (var f = 119; f < 130; f += 2)
                {
                    var skill = ELC.GetValue(38, n, f);

                    if (!skillTable.ContainsKey(skill)) continue;

                    ELC.SetValue(38, n, f, (string)skillTable[skill]);
                }
            }
        }

        private void ClickPropertyReplace(object sender, EventArgs e)
        {
            if (ELC == null) return;

            var load = new OpenFileDialog();
            load.InitialDirectory = Application.StartupPath + "\\replace";
            load.Filter = Resources.PropReplaceFilter;

            if (load.ShowDialog() != DialogResult.OK || !File.Exists(load.FileName)) return;

            var propertyTable = new SortedList();
            var sr = new StreamReader(load.FileName);
            var seperator = new[]{ "=" };

            while (!sr.EndOfStream)
            {
                var line = sr.ReadLine();

                if (line != null && (line.StartsWith("#") || !line.Contains("="))) continue;

                if (line == null) continue;

                var pair = line.Split(seperator, StringSplitOptions.RemoveEmptyEntries);

                if (pair.Length == 2) propertyTable.Add(pair[0], pair[1]);
            }

            sr.Close();

            string attribute;

            // weapons (list 3, fields 43-201, +=2)
            for (var i = 0; i < ELC.Lists[3].elementValues.Length; i++)
            {
                for (var j = 43; j < 202; j += 2)
                {
                    attribute = ELC.GetValue(3, i, j);

                    if (propertyTable.ContainsKey(attribute))
                        ELC.SetValue(3, i, j, (string) propertyTable[attribute]);
                }
            }

            // armors (list 6, fields 55-179, +=2)
            for (var i = 0; i < ELC.Lists[6].elementValues.Length; i++)
            {
                for (var j = 55; j < 180; j += 2)
                {
                    attribute = ELC.GetValue(6, i, j);

                    if (propertyTable.ContainsKey(attribute))
                        ELC.SetValue(6, i, j, (string) propertyTable[attribute]);
                }
            }

            // ornaments (list 9, fields 44-160, +=2)
            for (var i = 0; i < ELC.Lists[9].elementValues.Length; i++)
            {
                for (var j = 44; j < 161; j += 2)
                {
                    attribute = ELC.GetValue(9, i, j);

                    if (propertyTable.ContainsKey(attribute))
                        ELC.SetValue(9, i, j, (string) propertyTable[attribute]);
                }
            }

            // soulgems (list 35, fields 11-12, +=1)
            for (var i = 0; i < ELC.Lists[35].elementValues.Length; i++)
            {
                for (var j = 11; j < 13; j++)
                {
                    attribute = ELC.GetValue(35, i, j);

                    if (!propertyTable.ContainsKey(attribute)) continue;

                    ELC.SetValue(35, i, j, (string)propertyTable[attribute]);

                    switch ((string) propertyTable[attribute])
                    {
                        case "1515":
                            ELC.SetValue(35, i, j + 2, "Vit. +20");
                            break;

                        case "1517":
                            ELC.SetValue(35, i, j + 2, "Critical +2%");
                            break;

                        case "1518":
                            ELC.SetValue(35, i, j + 2, "Channel -6%");
                            break;
                    }
                }
            }

            // complect boni (list 90, fields 15-19, +=1)
            for (var i = 0; i < ELC.Lists[90].elementValues.Length; i++)
            {
                for (var j = 15; j < 20; j++)
                {
                    attribute = ELC.GetValue(90, i, j);

                    if (propertyTable.ContainsKey(attribute))
                        ELC.SetValue(90, i, j, (string) propertyTable[attribute]);
                }
            }
        }

        private void ClickTomeReplace(object sender, EventArgs e)
        {
            if (ELC == null) return;

            var load = new OpenFileDialog();
            load.InitialDirectory = Application.StartupPath + "\\replace";
            load.Filter = Resources.TomeReplaceFilter;

            if (load.ShowDialog() != DialogResult.OK || !File.Exists(load.FileName)) return;

            var propertyTable = new SortedList();
            var sr = new StreamReader(load.FileName);
            var seperator = new[]{ "=" };
            var divider = new[]{ "," };

            while (!sr.EndOfStream)
            {
                var line = sr.ReadLine();

                if (line == null || (line.StartsWith("#") || !line.Contains("="))) continue;

                var pair = line.Split(seperator, StringSplitOptions.RemoveEmptyEntries);

                if (pair.Length == 2)
                    propertyTable.Add(pair[0], pair[1].Split(divider, StringSplitOptions.RemoveEmptyEntries));
            }

            sr.Close();

            var attributesOrgiginal = new ArrayList();
            var attributesReplaced = new ArrayList();

            // weapons (list 3, fields 43-201, +=2)
            for (var i = 0; i < ELC.Lists[112].elementValues.Length; i++)
            {
                attributesOrgiginal.Clear();
                attributesReplaced.Clear();

                string attribute;
                for (var j = 4; j < 14; j++)
                {
                    attribute = ELC.GetValue(112, i, j);

                    if (attribute == "0") continue;

                    if (propertyTable.ContainsKey(attribute))
                    {
                        var attributes = (string[]) propertyTable[attribute];

                        foreach (var t in attributes)
                            attributesReplaced.Add(t);
                    }
                    else
                        // add the attribute without changes
                        attributesReplaced.Add(attribute);
                }

                if (attributesReplaced.Count > 10)
                    MessageBox.Show(Resources.TomeAttrOF + i + Resources.AttrTrunc);

                // add the new attribute list to the current tome
                for (var f = 4; f < 14; f++)
                {
                    if (f - 4 < attributesReplaced.Count)
                    {
                        // add the replaced attribute
                        attribute = (string) attributesReplaced[f - 4];
                        ELC.SetValue(112, i, f, attribute);
                    }
                    else
                        ELC.SetValue(112, i, f, "0");
                }
            }
        }

        private void ClickProbabilityValidate(object sender, EventArgs e)
        {
            if (ELC == null) return;

            var probabilities = new ArrayList();
            double attribute;

            // weapons (list 3)
            for (var i = 0; i < ELC.Lists[3].elementValues.Length; i++)
            {
                // weapon drop sockets count(fields 32-34, +=1)

                attribute = 0;

                for (var j = 32; j < 35; j++)
                    attribute += Convert.ToDouble(ELC.GetValue(3, i, j));

// ReSharper disable CompareOfFloatsByEqualityOperator
                if (Math.Round(attribute, 6) != 1)
// ReSharper restore CompareOfFloatsByEqualityOperator

                    probabilities.Add("Suspicious Socket Drop Probability (sum != 1.0): " +
                        attribute.ToString(CultureInfo.InvariantCulture) + " (Weapon: " +
                        ELC.GetValue(3, i, 0) + ")");

                // weapon craft sockets count(fields 35-37, +=1)

                attribute = 0;

                for (var j = 35; j < 38; j++)
                    attribute += Convert.ToDouble(ELC.GetValue(3, i, j));

// ReSharper disable CompareOfFloatsByEqualityOperator
                if (Math.Round(attribute, 6) != 1)
// ReSharper restore CompareOfFloatsByEqualityOperator

                    probabilities.Add("Suspicious Socket Craft Probability (sum != 1.0): " +
                        attribute.ToString(CultureInfo.InvariantCulture) +
                        " (Weapon: " + ELC.GetValue(3, i, 0) + ")");

                // weapon addons count(fields 38-41, +=1)

                attribute = 0;

                for (var j = 38; j < 42; j++)
                    attribute += Convert.ToDouble(ELC.GetValue(3, i, j));

// ReSharper disable CompareOfFloatsByEqualityOperator
                if (Math.Round(attribute, 6) != 1)
// ReSharper restore CompareOfFloatsByEqualityOperator

                    probabilities.Add("Suspicious Addon Count Probability (sum != 1.0): " +
                        attribute.ToString(CultureInfo.InvariantCulture) +
                        " (Weapon: " + ELC.GetValue(3, i, 0) + ")");

                // weapon drop (fields 44-106, +=2)

                attribute = 0;

                for (var j = 44; j < 107; j += 2)
                    attribute += Convert.ToDouble(ELC.GetValue(3, i, j));

// ReSharper disable CompareOfFloatsByEqualityOperator
                if (Math.Round(attribute, 6) != 1)
// ReSharper restore CompareOfFloatsByEqualityOperator

                    probabilities.Add("Suspicious Drop Attriutes Probability (sum != 1.0): " +
                        attribute.ToString(CultureInfo.InvariantCulture) + " (Weapon: " +
                        ELC.GetValue(3, i, 0) + ")");

                // weapon craft (fields 108-170, +=2)

                attribute = 0;

                for (var j = 108; j < 171; j += 2)
                    attribute += Convert.ToDouble(ELC.GetValue(3, i, j));

// ReSharper disable CompareOfFloatsByEqualityOperator
                if (Math.Round(attribute, 6) != 1)
// ReSharper restore CompareOfFloatsByEqualityOperator

                    probabilities.Add("Suspicious Craft Attributes Probability (sum != 1.0): " +
                        attribute.ToString(CultureInfo.InvariantCulture) + " (Weapon: " +
                        ELC.GetValue(3, i, 0) + ")");

                // weapons unique (fields 172-202, +=2)

                attribute = 0;

                for (var j = 172; j < 203; j += 2)
                    attribute += Convert.ToDouble(ELC.GetValue(3, i, j));

// ReSharper disable CompareOfFloatsByEqualityOperator
                if (Math.Round(attribute, 6) != 1)
// ReSharper restore CompareOfFloatsByEqualityOperator

                    probabilities.Add("Suspicious Unique Attributes Probability (sum != 1.0): " +
                        attribute.ToString(CultureInfo.InvariantCulture) + " (Weapon: " +
                        ELC.GetValue(3, i, 0) + ")");
            }

            // armors (list 6)
            for (var i = 0; i < ELC.Lists[6].elementValues.Length; i++)
            {
                // armor drop sockets count(fields 41-45, +=1)

                attribute = 0;

                for (var j = 41; j < 46; j++)
                    attribute += Convert.ToDouble(ELC.GetValue(6, i, j));

// ReSharper disable CompareOfFloatsByEqualityOperator
                if (Math.Round(attribute, 6) != 1)
// ReSharper restore CompareOfFloatsByEqualityOperator

                    probabilities.Add("Suspicious Socket Drop Probability (sum != 1.0): " +
                        attribute.ToString(CultureInfo.InvariantCulture) +
                        " (Armor: " + ELC.GetValue(6, i, 0) + ")");

                // armor craft sockets count(fields 46-50, +=1)

                attribute = 0;

                for (var j = 46; j < 51; j++)
                    attribute += Convert.ToDouble(ELC.GetValue(6, i, j));

// ReSharper disable CompareOfFloatsByEqualityOperator
                if (Math.Round(attribute, 6) != 1)
// ReSharper restore CompareOfFloatsByEqualityOperator

                    probabilities.Add("Suspicious Socket Craft Probability (sum != 1.0): " +
                        attribute.ToString(CultureInfo.InvariantCulture) +
                        " (Armor: " + ELC.GetValue(6, i, 0) + ")");

                // armor addons count(fields 51-54, +=1)

                attribute = 0;

                for (var j = 51; j < 55; j++)
                    attribute += Convert.ToDouble(ELC.GetValue(6, i, j));

// ReSharper disable CompareOfFloatsByEqualityOperator
                if (Math.Round(attribute, 6) != 1)
// ReSharper restore CompareOfFloatsByEqualityOperator

                    probabilities.Add("Suspicious Addon Count Probability (sum != 1.0): " +
                        attribute.ToString(CultureInfo.InvariantCulture) +
                        " (Armor: " + ELC.GetValue(6, i, 0) + ")");

                // armor drop (fields 56-118, +=2)

                attribute = 0;

                for (var j = 56; j < 119; j += 2)
                    attribute += Convert.ToDouble(ELC.GetValue(6, i, j));

// ReSharper disable CompareOfFloatsByEqualityOperator
                if (Math.Round(attribute, 6) != 1)
// ReSharper restore CompareOfFloatsByEqualityOperator

                    probabilities.Add("Suspicious Drop Attriutes Probability (sum != 1.0): " +
                        attribute.ToString(CultureInfo.InvariantCulture) + " (Armor: " +
                        ELC.GetValue(6, i, 0) + ")");

                // armor craft (fields 120-180, +=2)

                attribute = 0;

                for (var j = 120; j < 181; j += 2)
                    attribute += Convert.ToDouble(ELC.GetValue(6, i, j));

// ReSharper disable CompareOfFloatsByEqualityOperator
                if (Math.Round(attribute, 6) != 1)
// ReSharper restore CompareOfFloatsByEqualityOperator

                    probabilities.Add("Suspicious Craft Attributes Probability (sum != 1.0): " +
                        attribute.ToString(CultureInfo.InvariantCulture) +
                        " (Armor: " + ELC.GetValue(6, i, 0) + ")");
            }

            // ornaments (list 9)
            for (var i = 0; i < ELC.Lists[9].elementValues.Length; i++)
            {
                // ornament addons count(fields 40-43, +=1)

                attribute = 0;

                for (var j = 40; j < 44; j++)
                    attribute += Convert.ToDouble(ELC.GetValue(9, i, j));

// ReSharper disable CompareOfFloatsByEqualityOperator
                if (Math.Round(attribute, 6) != 1)
// ReSharper restore CompareOfFloatsByEqualityOperator

                    probabilities.Add("Suspicious Addon Count Probability (sum != 1.0): " +
                        attribute.ToString(CultureInfo.InvariantCulture) +
                        " (Ornament: " + ELC.GetValue(9, i, 0) + ")");

                // ornament drop (fields 45-107, +=2)

                attribute = 0;

                for (var j = 45; j < 108; j += 2)
                    attribute += Convert.ToDouble(ELC.GetValue(9, i, j));

// ReSharper disable CompareOfFloatsByEqualityOperator
                if (Math.Round(attribute, 6) != 1)
// ReSharper restore CompareOfFloatsByEqualityOperator

                    probabilities.Add("Suspicious Drop Attriutes Probability (sum != 1.0): " +
                        attribute.ToString(CultureInfo.InvariantCulture) +
                        " (Ornament: " + ELC.GetValue(9, i, 0) + ")");

                // ornament craft (fields 109-161, +=2)

                attribute = 0;

                for (var j = 109; j < 162; j += 2)
                    attribute += Convert.ToDouble(ELC.GetValue(9, i, j));

// ReSharper disable CompareOfFloatsByEqualityOperator
                if (Math.Round(attribute, 6) != 1)
// ReSharper restore CompareOfFloatsByEqualityOperator

                    probabilities.Add("Suspicious Craft Attributes Probability (sum != 1.0): " +
                        attribute.ToString(CultureInfo.InvariantCulture) +
                        " (Ornament: " + ELC.GetValue(9, i, 0) + ")");
            }

            if (probabilities.Count == 0)
                MessageBox.Show(Resources.OkNoInvalidProb);
            else
            {
                var message = probabilities.Cast<object>().Aggregate("", (current, t) => current + ((string) t + "\r\n"));

// ReSharper disable ObjectCreationAsStatement
                new DebugWindow("Invalid Probabilities", message);
// ReSharper restore ObjectCreationAsStatement
            }
        }

        private void ClickTaskOverflowCheck(object sender, EventArgs e)
        {
            if (ELC == null) return;

            string value;
            bool isAddedElement;

            var questWindow = new LostQuestWindow();

            // list 45 recive quests
            for (var i = 0; i < ELC.Lists[45].elementValues.Length; i++)
            {
                isAddedElement = false;
                for (var j = 34; j < ELC.Lists[45].elementFields.Length; j++)
                {
                    value = ELC.GetValue(45, i, j);

                    if (value == "0") continue;

                    if (!isAddedElement)
                    {
                        questWindow.listBox_Receive.Items.Add("+++++ " + ELC.GetValue(45, i, 0) + " - " + ELC.GetValue(45, i, 1) + " +++++");
                        isAddedElement = true;
                    }
                    questWindow.listBox_Receive.Items.Add(value);
                }
            }

            // list 46 activate quests
            for (var i = 0; i < ELC.Lists[46].elementValues.Length; i++)
            {
                isAddedElement = false;
                for (var j = 34; j < ELC.Lists[46].elementFields.Length; j++)
                {
                    value = ELC.GetValue(46, i, j);

                    if (value == "0") continue;

                    if (!isAddedElement)
                    {
                        questWindow.listBox_Activate.Items.Add("+++++ " + ELC.GetValue(46, i, 0) + " - " + ELC.GetValue(46, i, 1) + " +++++");
                        isAddedElement = true;
                    }
                    questWindow.listBox_Activate.Items.Add(value);
                }
            }
            questWindow.Show();
        }

        private void ClickClassMask(object sender, EventArgs e)
        {
            var eClassMask = new ClassMaskWindow();
            eClassMask.Show();
        }

        private void CellMouseMoveToolTip(object sender, DataGridViewCellMouseEventArgs e)
{
            if (comboBox_ELLists.SelectedIndex == 0 && listBox_ELItems.SelectedIndex !=
                -1 && e.ColumnIndex == 2 && e.RowIndex > 2 && e.RowIndex < 6)
            {
                var text = "Float: " +
                    (BitConverter.ToSingle(BitConverter.GetBytes((int) (ELC.Lists[0].
                    elementValues[listBox_ELItems.SelectedIndex][e.RowIndex])), 0)).ToString("F6");

                // not working on first mouse over (still shows previous value on first mouse over)
                //dataGridView_item->Rows[e->RowIndex]->Cells[e->ColumnIndex]->ToolTipText = text;

                // only draw on real move to prevent flickering in windows 7
                if (mouseMoveCheck.X != e.X || mouseMoveCheck.Y != e.Y)
                {
                    toolTip.SetToolTip((Control) sender, text);
                    mouseMoveCheck.X = e.X;
                    mouseMoveCheck.Y = e.Y;
                }
            }
            else
                toolTip.Hide((Control) sender);
}

        private void ClickDiffEL(object sender, EventArgs e)
        {
            var eRules = new RulesWindow();
            eRules.Show();
        }

        private void InitializeELMenu()
        {
            LoadELMenuItem.DropDownItems.Add(new ToolStripLabel("Select a Version"));
            JoinNewElements.DropDownItems.Add(new ToolStripLabel("Select a Version"));
            LoadELMenuItem.DropDownItems[0].Font = new Font("Tahoma", 8.25f, FontStyle.Bold, GraphicsUnit.Point, 0);
            JoinNewElements.DropDownItems[0].Font = new Font("Tahoma", 8.25f, FontStyle.Bold, GraphicsUnit.Point, 0);
            LoadELMenuItem.DropDownItems.Add(new ToolStripSeparator());
            JoinNewElements.DropDownItems.Add(new ToolStripSeparator());

            var files = Directory.GetFiles(Application.StartupPath + "\\configs", "*.cfg");

            for (var i = 0; i < files.Length; i++)
            {
                files[i] = files[i].Replace(".cfg", "");
                files[i] = files[i].Replace(Application.StartupPath + "\\configs\\", "");
                LoadELMenuItem.DropDownItems.Add(files[i], null, ClickLoad);
                JoinNewElements.DropDownItems.Add(files[i], null, ClickJoinEL);
            }

            ELExportMenuItem.DropDownItems.Add(new ToolStripLabel("Select a valid Conversation Rules Set"));
            ELExportMenuItem.DropDownItems[0].Font = new Font("Tahoma", 8.25f, FontStyle.Bold, GraphicsUnit.Point, 0);
            ELExportMenuItem.DropDownItems.Add(new ToolStripSeparator());
            files = Directory.GetFiles(Application.StartupPath + "\\rules", "*.rules");

            for (var j = 0; j < files.Length; j++)
            {
                files[j] = files[j].Replace("=", "==>");
                files[j] = files[j].Replace(".rules", "");
                files[j] = files[j].Replace(Application.StartupPath + "\\rules\\", "");
                ELExportMenuItem.DropDownItems.Add(files[j], null, ClickExport);
            }
        }
        
    }
}
